package com.kingsoft.demo.xml.digester;

import java.io.File;
import java.io.IOException;

import org.apache.commons.digester.Digester;
import org.xml.sax.SAXException;

/**
 * XML-->Java Object
 * @author kbl
 *
 */
public class DigesterDriver {
	
	public static void main(String[] args) {
		
		Digester digester = new Digester();   
		digester.setValidating( false );
		
		digester.addObjectCreate("catalog", Catalog.class);
		digester.addObjectCreate("catalog/book", "com.kingsoft.demo.xml.digester.Book");
		
		digester.addBeanPropertySetter( "catalog/book/author", "author" );   
		digester.addBeanPropertySetter( "catalog/book/title", "title" );   
		digester.addSetNext( "catalog/book", "addBook" );   
		
		//digester.addCallMethod(pattern, methodName)
		
		//String str = DigesterDriver.class.getClassLoader().getResource("com/sun/demo/catalog.xml").getFile();
	
		String str = DigesterDriver.class.getResource("catalog.xml").getFile();
		
		File input = new File(str);
		try {
			Catalog c = (Catalog)digester.parse(input);
			System.out.println(c);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		
	}   
	

}
